
#ifndef BUILD_ORDER_H_
#define BUILD_ORDER_H_

#include <BWAPI.h>
#include <map>
#include <string>

enum ORDERS
{
	BUILD_BUILDIDNG,
	BUILD_UNIT,
	BUILD_ADDON,
	EXPAND,
	RESEARCH
};

struct Order
{
	int atSupply;
	BWAPI::UnitType typeToBuild;
	int howManyUnits;
	ORDERS order;
};

class BuildOrder
{
public:
	BuildOrder(std::string incName, BWAPI::UnitType defaultUnit = BWAPI::UnitTypes::Terran_SCV, Order* orders = NULL, int buildOrderLength = 0)	:	defaultUnitType(defaultUnit),
																																				name(incName)
	{
		if(orders)
		{
			for(int i = 0; i < buildOrderLength; i++)
				buildOrder[orders[i].atSupply] = orders[i];
		}
		defaultOrder.atSupply = -1;
		defaultOrder.typeToBuild = BWAPI::UnitTypes::Terran_SCV;
		defaultOrder.howManyUnits = 1;
		defaultOrder.order = BUILD_UNIT;
	}

	void AddOrder(Order* order)
	{
		std::map<int,Order>::iterator it = buildOrder.find(order->atSupply);
		if(it == buildOrder.end())
		{
			buildOrder[order->atSupply] = *order;
		}
	}

	Order* GetOrder(int supply)
	{
		std::map<int,Order>::iterator it = buildOrder.find(supply);
		if(it != buildOrder.end())
		{
			return &(it->second);
		}
		return &defaultOrder;
	}

	void ResetOrder(int supply)
	{
		std::map<int,Order>::iterator it = buildOrder.find(supply);
		if(it != buildOrder.end())
		{
			buildOrder.erase(it);
		}
	}

private:
	std::map<int,Order> buildOrder;
	BWAPI::UnitType defaultUnitType;
	std::string name;
	Order defaultOrder;
};


#endif
